Skip to content

[feat] declarative TUF - #2679

Draft
bouskaJ wants to merge 1 commit into
declarative_tuf_apifrom
tuf_baseline
Draft

bouskaJ wants to merge 1 commit into
declarative_tuf_apifrom
tuf_baseline

Conversation

@bouskaJ

@bouskaJ bouskaJ commented Dec 3, 2026

Copy link
Copy Markdown
Member

No description provided.

@codecov-commenter

codecov-commenter commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.06876% with 227 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.93%. Comparing base (9dc7084) to head (2e77a11).

Files with missing lines Patch % Lines
...ler/tuf/actions/trustrootsync/detect_sync_drift.go 79.24% 41 Missing and 3 partials ⚠️
...l/controller/tuf/actions/trustrootsync/baseline.go 35.38% 42 Missing ⚠️
.../tuf/actions/trustrootsync/process_sync_results.go 82.14% 28 Missing and 2 partials ⚠️
internal/controller/tuf/trustroot/resolver.go 74.54% 24 Missing and 4 partials ⚠️
internal/controller/tuf/utils/tuf_migration_job.go 0.00% 25 Missing ⚠️
internal/controller/tuf/actions/fips_validation.go 0.00% 22 Missing ⚠️
internal/utils/kubernetes/job/job.go 0.00% 12 Missing ⚠️
internal/controller/tuf/trustroot/helpers.go 0.00% 9 Missing ⚠️
...ternal/controller/securesign/actions/ensure_tuf.go 0.00% 8 Missing ⚠️
...al/controller/tuf/actions/trustrootsync/helpers.go 82.14% 5 Missing ⚠️
... and 2 more
Additional details and impacted files
@@                   Coverage Diff                   @@
##           declarative_tuf_api    #2679      +/-   ##
=======================================================
- Coverage                59.46%   53.93%   -5.54%     
=======================================================
  Files                      302      305       +3     
  Lines                    17715    18130     +415     
=======================================================
- Hits                     10534     9778     -756     
- Misses                    6417     7488    +1071     
- Partials                   764      864     +100     
Flag Coverage Δ
e2e 48.55% <55.40%> (-27.11%) ⬇️
unit 42.60% <53.66%> (+0.30%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bouskaJ
bouskaJ force-pushed the tuf_baseline branch 2 times, most recently from 88d77d5 to 74e74d1 Compare December 3, 2026 13:57
@bouskaJ
bouskaJ marked this pull request as ready for review December 3, 2026 13:58
@bouskaJ
bouskaJ marked this pull request as draft December 3, 2026 13:58
@qodo-for-securesign

qodo-for-securesign Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Declarative TUF: trust root baseline, sync job, and drift detection

✨ Enhancement 🧪 Tests ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Replaces the per-key resolve-keys action with a declarative trust root resolver and
 published-state tracking.
• Adds a baseline action and a drift-detecting sync Job that applies JSON patches via `tufcli rhtas
 apply`.
• Updates e2e tests, CI workflow, RBAC (pods list), and the TUF init image reference for the new
 flow.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 3 capabilities

  • 3 affected capabilities within one bounded functional scope: TUF trust-root integration.
  • The controller, resolver, sync Job, status fields, Secrets, and TUF repository are one bounded integration producing the published trust-root document; these are propagation hops rather than independent capabilities.
  • Initialization and migration are distinct lifecycle operations within the same bounded TUF integration: both create or transform the repository consumed by the TUF service and use the same root-key, component-binding, and repository-volume boundary.
  • This validation gates the same TUF trust-root lifecycle and examines its configured and materialized component Secrets; it does not independently publish or consume another functional domain.
Behavioral complexity 🔴 High 🧩 Multiple interactions

  • Before, key resolution and repository initialization were handled in the normal action sequence.
  • After, baseline reconstruction, desired/actual resolution, JSON patch generation, Job execution, succeeded-Pod result parsing, Secret materialization, status persistence, and Job cleanup interact.
  • New correctness conditions are that the Job patch matches the observed repository version, only the corresponding completed Job is adopted, materialized bindings agree with published status, and legacy v1 state transitions without losing the existing repository.
  • The async failure, retry, deletion, and persistent-state branches are newly coordinated; resolver maps and existing validation are reused infrastructure, not complexity by themselves.
Potential damage 🟡 Medium 🩹 Temporary loss

  • If synchronization regresses, the TUF repository can remain stale or unavailable to verification clients.
  • Reverting code stops new failures, but a partially published repository or adopted Secret may require a subsequent sync or manual repair.
  • A failed Job is deleted and retried through reconciliation; successful but incorrect persistent repository state requires a later corrective synchronization, and external clients may need to refresh metadata.
Assessed commit 74e74d1
Diagram

graph TD
  RC["TUF reconciler"] --> BL["Baseline action"] --> DD["Detect drift action"] --> RS["trustroot.Resolve"] --> JP["JSON patch diff"] --> JOB["trust-root-sync Job"] --> PR["Process sync results"] --> ST[("Status.TrustRoot")]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Synchronous publish inside the reconciler
  • ➕ No Job lifecycle, retry, or result-parsing logic
  • ➕ Fewer status states such as SyncInProgress
  • ➖ Needs key material and repository PVC access in the operator process
  • ➖ Blocks reconciliation on tufcli execution time
  • ➖ Harder to isolate failures and debug
2. Separate TrustRoot CRD owned by Tuf
  • ➕ Clear ownership of published trust root state
  • ➕ Independent status and conditions
  • ➖ New API surface and CRD lifecycle to maintain
  • ➖ More cross-controller coordination for a single feature

Recommendation: The PR's approach is reasonable. Publication is asynchronous, uses a Job, and keeps the desired-vs-published comparison on the operator side, which avoids blocking reconciliation and keeps key material out of the controller. The main alternative is a synchronous in-reconciler publish, which is simpler but needs the key volume and PVC mounted into the operator and risks long reconciles. Another option is a separate TrustRoot CRD, which gives cleaner ownership but adds an API and lifecycle surface the PR does not need yet.

Files changed (38) +1413 / -1326

Enhancement (6) +148 / -21
fips_validation.goValidate FIPS crypto refs across all trust root component bindings +31/-12

Validate FIPS crypto refs across all trust root component bindings

• Collects secretRefs from ctlog, fulcio, rekor, and tsa bindings instead of only active keys. Status key secrets are skipped only when a spec binding already references the same secret name, so they are not validated twice.

internal/controller/tuf/actions/fips_validation.go

constants.goAdd trust root sync condition and reason constants +7/-0

Add trust root sync condition and reason constants

• Adds TrustRootSynced condition type, plus SyncInProgress, Synchronized, and Unknown reason constants used by the sync actions.

internal/controller/tuf/constants/constants.go

helpers.goAdd legacy binding lookup helper for migration paths +27/-0

Add legacy binding lookup helper for migration paths

• Adds LegacyBinding, which finds a binding by target name or returns the single unnamed legacy binding, falling back to autodiscovery. Used by the baseline action and the migration job.

internal/controller/tuf/trustroot/helpers.go

types.goAdd TrustRootBinder interface and resolved document types +58/-0

Add TrustRootBinder interface and resolved document types

• Defines TrustRootBinder, ResolvedBinding, ResolvedValidity, ResolvedComponents, and ResolvedTrustRootDocument. These are the JSON-serializable shapes used for desired and actual comparison and for the sync Job patch.

internal/controller/tuf/trustroot/types.go

tuf_controller.goWire baseline and drift actions into TUF reconciler +7/-9

Wire baseline and drift actions into TUF reconciler

• Removes the resolve-keys action and the active-key condition supplier, then adds the baseline action before deploy and the process-results and drift actions in the Ready phase. The Ready-phase sync does not cause downtime and reports through its own condition.

internal/controller/tuf/tuf_controller.go

job.goAdd helper to list succeeded Job pods +18/-0

Add helper to list succeeded Job pods

• Adds FindSuceededPods, which lists pods by controller-uid label and returns those in PodSucceeded phase. Used to read the sync Job's termination message. The function name has a typo.

internal/utils/kubernetes/job/job.go

Refactor (7) +197 / -397
migration_job.goAdjust migration job action for new utils signature +2/-1

Adjust migration job action for new utils signature

• Changes two lines and removes one, aligning the migration job action with the reworked utils helper. Details are not expanded here.

internal/controller/tuf/actions/migration_job.go

resolve_keys.goDelete resolve-keys action +0/-160

Delete resolve-keys action

• Removes the resolveKeysAction that resolved per-key addresses and material, created the tuf-keys-<name> secret, and populated status.keys. Its role is replaced by the trust root resolver and the baseline and drift actions.

internal/controller/tuf/actions/resolve_keys.go

tuf_init_job.goAdjust init job action for new utils signature +2/-1

Adjust init job action for new utils signature

• Changes two lines and removes one to match the reworked init job utils. Details are not expanded here.

internal/controller/tuf/actions/tuf_init_job.go

resolver.goRewrite trust root resolver around bindings and TUF target documents +160/-148

Rewrite trust root resolver around bindings and TUF target documents

• Replaces per-ComponentKey descriptors with generic ResolveBinding over a TrustRootBinder interface, plus Resolve that builds a ResolvedTrustRootDocument. Adds explicit-binding validation (ref or URL with hostname, plus secretRef) and MaterializeBinding helpers to rewrite refs into URLs and secrets.

internal/controller/tuf/trustroot/resolver.go

common.goRemove obsolete shared helper code +0/-24

Remove obsolete shared helper code

• Deletes 24 lines of helper code that the rewritten trust root path no longer uses.

internal/controller/tuf/utils/common.go

tuf_init_job.goDrop key secret mounts from TUF init job +3/-40

Drop key secret mounts from TUF init job

• Removes the secret mount path and per-key trust root resolution from the init job. Init no longer receives key material, which is now handled by the sync Job.

internal/controller/tuf/utils/tuf_init_job.go

tuf_migration_job.goResolve migration env from legacy bindings and add OIDC issuers +30/-23

Resolve migration env from legacy bindings and add OIDC issuers

• Resolves REKOR_URL, CTLOG_URL, FULCIO_URL, and OIDC_ISSUERS from legacy bindings via LegacyBinding and serviceresolver. Adds TSA_URL only when a TSA is configured.

internal/controller/tuf/utils/tuf_migration_job.go

Tests (18) +545 / -857
migration_job_test.goAdd test setup for migration job +4/-0

Add test setup for migration job

• Adds four lines of test setup for the migration job action.

internal/controller/tuf/actions/migration_job_test.go

resolver_test.goUpdate resolver tests for binding-based API +63/-36

Update resolver tests for binding-based API

• Updates existing resolver tests for the new ResolveBinding and Resolve signatures and adds cases for explicit-binding validation.

internal/controller/tuf/trustroot/resolver_test.go

tuf_controller_test.goUpdate TUF controller tests for new action pipeline +129/-83

Update TUF controller tests for new action pipeline

• Updates controller tests for the new action order and the TrustRootSynced condition. Net change is 129 lines added and 83 removed.

internal/controller/tuf/tuf_controller_test.go

ctlog_sharding_test.goUpdate ctlog sharding e2e test for declarative TUF +22/-18

Update ctlog sharding e2e test for declarative TUF

• Changes 22 lines and removes 18 to match the new TUF status model. Details are not expanded here.

test/e2e/install/ctlog_sharding_test.go

key_autodiscovery_test.goUpdate key autodiscovery e2e test for declarative TUF +27/-31

Update key autodiscovery e2e test for declarative TUF

• Changes 27 lines and removes 31 to match the new TUF status model. Details are not expanded here.

test/e2e/install/key_autodiscovery_test.go

provided_certs_test.goUpdate provided certs e2e test for declarative TUF +43/-44

Update provided certs e2e test for declarative TUF

• Changes 43 lines and removes 44 to match the new TUF status model. Details are not expanded here.

test/e2e/install/provided_certs_test.go

file_kms_migration_test.goTrim file KMS migration e2e test +9/-123

Trim file KMS migration e2e test

• Removes 123 lines and adds 9 in the file KMS migration e2e test.

test/e2e/lifecycle/file_kms_migration_test.go

key_rotation_test.goRemove tufcli-based key rotation verification +18/-230

Remove tufcli-based key rotation verification

• Removes 230 lines, including tufcli CLI, key-handling, and trillian keyspb imports. Verification relies on the controller's declarative status.

test/e2e/lifecycle/key_rotation_test.go

kms_file_migration_test.goTrim KMS file migration e2e test +7/-116

Trim KMS file migration e2e test

• Removes 116 lines and adds 7 in the KMS file migration e2e test.

test/e2e/lifecycle/kms_file_migration_test.go

ctlog_monitor_log_test.goAdjust ctlog monitor log e2e test +3/-4

Adjust ctlog monitor log e2e test

• Changes three lines and removes four to match the new TUF wiring.

test/e2e/monitoring/ctlog_monitor_log_test.go

ctlog_monitor_test.goAdjust ctlog monitor e2e test +3/-4

Adjust ctlog monitor e2e test

• Changes three lines and removes four to match the new TUF wiring.

test/e2e/monitoring/ctlog_monitor_test.go

rekor_monitor_log_test.goAdjust rekor monitor log e2e test +3/-4

Adjust rekor monitor log e2e test

• Changes three lines and removes four to match the new TUF wiring.

test/e2e/monitoring/rekor_monitor_log_test.go

rekor_monitor_test.goAdjust rekor monitor e2e test +3/-4

Adjust rekor monitor e2e test

• Changes three lines and removes four to match the new TUF wiring.

test/e2e/monitoring/rekor_monitor_test.go

tuf.goUpdate TUF e2e support helpers for declarative bindings +123/-92

Update TUF e2e support helpers for declarative bindings

• Reworks the TUF e2e support helpers, removing 92 lines and adding 123. The helpers that wrapped the tufcli binary are reworked for the declarative binding model.

test/e2e/support/tas/tuf/tuf.go

ctlog_test.goUpdate ctlog update e2e test for trust root sync +24/-17

Update ctlog update e2e test for trust root sync

• Changes 24 lines and removes 17. Details are not expanded here.

test/e2e/update/ctlog_test.go

fulcio_test.goUpdate fulcio update e2e test for trust root sync +22/-17

Update fulcio update e2e test for trust root sync

• Changes 22 lines and removes 17. Details are not expanded here.

test/e2e/update/fulcio_test.go

rekor_test.goUpdate rekor update e2e test for trust root sync +21/-17

Update rekor update e2e test for trust root sync

• Changes 21 lines and removes 17. Details are not expanded here.

test/e2e/update/rekor_test.go

tsa_test.goUpdate TSA update e2e test for trust root sync +21/-17

Update TSA update e2e test for trust root sync

• Changes 21 lines and removes 17. Details are not expanded here.

test/e2e/update/tsa_test.go

Other (7) +523 / -51
main.ymlRemove tufcli build job and wait for trustroot-synced in kind test +1/-50

Remove tufcli build job and wait for trustroot-synced in kind test

• Deletes the build-tufcli job and its artifact download and PATH setup from the kind test. Adds a kubectl wait for the trustroot-synced condition after the Securesign sample becomes Ready.

.github/workflows/main.yml

images.envPoint TUF init image to a developer quay.io tag +1/-1

Point TUF init image to a developer quay.io tag

• Replaces the RELATED_IMAGE_TUF registry.redhat.io tufcli-init image with quay.io/jbouska/securesign-controller:tuf-init3. This is a personal dev image and must be replaced with a released image before merge.

config/default/images.env

role.yamlGrant core pods get/list permission +1/-0

Grant core pods get/list permission

• Adds pods to the core API group rule that already grants get and list on namespaces. Needed so the controller can find succeeded sync Job pods to read the tufcli result.

config/rbac/role.yaml

baseline.goAdd one-time baseline action for trust root publication state +106/-0

Add one-time baseline action for trust root publication state

• On first run in Ready phase, reconstructs status.trustRoot.published from legacy status.keys and spec bindings, resolving service URLs and Fulcio OIDC issuers. It then clears status.keys and sets the TrustRootSynced condition to Unknown/Pending.

internal/controller/tuf/actions/trustrootsync/baseline.go

detect_sync_drift.goDetect desired vs published drift and launch sync Job +226/-0

Detect desired vs published drift and launch sync Job

• Resolves desired bindings from spec and actual bindings from status.trustRoot.published, then compares them. On drift it creates a trust-root-sync Job that runs tufcli rhtas apply with a JSON patch (guarded by an apiVersion test op), signing keys from the root key secret, and the repository PVC.

internal/controller/tuf/actions/trustrootsync/detect_sync_drift.go

process_sync_results.goProcess sync Job results and materialize published bindings +187/-0

Process sync Job results and materialize published bindings

• Handles sync Job completion and failure, parses the desired-components and observed-generation annotations, and deletes the Job after it finishes. On success it creates immutable secrets for ref-based bindings, rewrites them as URL and secretRef, and stores the published state and target version in status.

internal/controller/tuf/actions/trustrootsync/process_sync_results.go

types.goRegister trustroot-synced condition type +1/-0

Register trustroot-synced condition type

• Adds one line to the controller condition types so the TrustRootSynced condition is recognized.

internal/controller/types.go

@qodo-for-securesign

qodo-for-securesign Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Code Review by Qodo


Action required

1. Fresh repositories omit signing trust 🔗 Cross-repo conflict
Description
EnsureTufInitJob no longer passes component certificates, keys, or URLs to tuf-repo-init.sh,
whose component-target additions run only when those arguments are supplied. A fresh installation
therefore initially serves a repository without the trust targets that policy-controller-operator's
RHTAS TUF reader requests, before any later sync can populate them.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Fresh TUF initialization now omits the component targets consumed by other repositories.
## Fix Focus Areas
- internal/controller/tuf/utils/tuf_init_job.go[23-45]
- /cross_repos/tufcli/rhtas/tuf-repo-init.sh[194-239]
- /cross_repos/policy-controller-operator/test/utils/rhtas.go[90-106]
## Recommended Fix
Restore component material and arguments to initialization, or make initial declarative publication succeed before exposing the repository as ready. Verify a new installation serves the canonical trust targets.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

2. Trust updates never reach TUF 🔗 Cross-repo conflict
Description
The sync job invokes tufcli rhtas apply --input, but the tufcli repository defines neither an
apply subcommand nor an --input flag. Whenever a binding differs from the published state,
tufcli rejects the job instead of publishing the patch.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The operator runs a declarative patch command that the tufcli image does not support.
## Fix Focus Areas
- internal/controller/tuf/actions/trustrootsync/detect_sync_drift.go[178-195]
- /cross_repos/tufcli/cmd/rhtas.go[76-93]
- /cross_repos/tufcli/cmd/rhtas.go[174-233]
## Recommended Fix
Either implement and release patch application in tufcli and select that image in the operator, or translate the desired changes into supported tufcli flags and inputs. Test the resulting command against the selected container image.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Remediation recommended

3. Renamed targets break TUF readers 🔗 Cross-repo conflict
Description
resolveBindings publishes targets under each configured TargetName, including names derived from
a service reference, without preserving the canonical filename. For such a configuration,
policy-controller-operator's RHTAS integration reader requests fixed target names and fails when a
required canonical target is absent.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Configurable target names can remove filenames used by a cross-repository TUF reader.
## Fix Focus Areas
- internal/controller/tuf/trustroot/resolver.go[187-200]
- api/v1/tuf_defaults.go[35-65]
- /cross_repos/policy-controller-operator/test/utils/rhtas.go[25-46]
- /cross_repos/policy-controller-operator/test/utils/rhtas.go[90-106]
## Recommended Fix
Keep the canonical trust targets available when publishing additional named bindings, or coordinate an updated target-discovery contract with the consumers. Add a cross-repository test using a binding with a noncanonical name.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗

4. Migration and baseline ignore configured component refs 🐞 Bug
Description
LegacyBinding matches only bindings whose TargetName equals the legacy key (e.g. rekor.pub) or
a single unnamed binding. Bindings that come from Securesign defaults carry a ref and are defaulted
to rekor-<ref>.pub, so they never match and an empty binding is returned. EnsureTufMigrationJob
and the baseline reconstructPublished then autodiscover by listing CRs in the Tuf namespace
instead of using the configured ref, unlike the old Binding, which took the first entry.
Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
LegacyBinding returns an empty (autodiscovery) binding for ref-based bindings whose defaulted TargetName differs from the legacy key, so the configured refs are dropped.

## Fix Focus Areas
- internal/controller/tuf/trustroot/helpers.go[16-27]

## Recommended Fix
After the exact-name lookup, fall back to `bindings[0]` whenever `len(bindings) > 0`, which matches the old `firstBinding` behaviour. Return an empty binding only when the list is empty.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants